#define _CRT_SECURE_NO_WARNINGS 1
#include "SeqList.h"
#include "contact.h"
void SLInit(SL* s){

	s->a = NULL;
	s->capacity = 0;
	s->size = 0;
}
void SLDestroy(SL* s) {
if (s->a != NULL)
	free(s->a);
	s->a = NULL;
	s->capacity = s->size = 0;
}
void SLCheckCapacity(SL* s){

	
	if (s->size == s->capacity){
	
		int newcapacity = s->capacity == 0 ? 4 : 2 * s->capacity;
		SLDataType* tmp = (SLDataType*)realloc(s->a, newcapacity*sizeof(SLDataType));
		if (tmp == NULL){
			perror("realloc");
			return 1;
		}
		s->a = tmp;
		s->capacity = newcapacity;
	}

}
void SLPushBack(SL* s, SLDataType x){
	assert(s);
	SLCheckCapacity(s);
	s->a[s->size] = x;
	s->size++;
}
void SLPushFront(SL* s, SLDataType x){

	assert(s);
	SLCheckCapacity(s);
	for (size_t i = s->size ; i > 0; i--){
		s->a[i] = s->a[i-1];

	}
	s->a[0] = x;
	s->size++;
}
void SLPopBack(SL* s){

	assert(s);
	assert(!SLIsEmpty);
	s->size--;
}
bool SLIsEmpty(SL* s){
	return s->size == 0;
}
void SLPopFront(SL* s){
	assert(s);
	assert(!SLIsEmpty);
	for (size_t i = 0; i < s->size-1; i++){
	
		s->a[i] = s->a[i + 1];
	}
	s->size--;
}
void SLInsert(SL* s, int pos, SLDataType x){

	assert(s);
	SLCheckCapacity(s);
	if (pos >= 0 && pos <= s->size - 1){
	
		for (size_t i = s->size - 1; i>pos-1; i--)
		{
			s->a[i+1] = s->a[i];
		}
		s->a[pos] = x;
		s->size++;
	}
}
void SLErase(SL* s, int pos){

	assert(s);
	assert(pos >= 0 && pos <= s->size);
	for (size_t i = pos; i < s->size-1; i++){
		s->a[i] = s->a[i+1];
		}
	
	s->size--;
}
void SLPrint(SL* s){

	
	for (size_t i = 0; i < s->size; i++){
	printf("%d ", s->a[i]);
	}
}